package View;
import Model.*;
import Persistencia.AdministradorPersistenciaAutomovil;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import Controller.Sistema;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class BajaAutomovil extends javax.swing.JFrame {
	private static String titulo = "Baja Automovil";
	AutomovilView auto2;
	private JLabel jLabel1;
	private JTextField campopatente;
	private JPanel jPanel1;
	private JLabel jLabel3;
	private JTextField campoestado;
	private JButton jButton1;
	private JTextField combcampo;
	private JLabel jLabel4;
	private JTextField kmcampo;
	private JLabel jLabel2;
	private JButton buscarboton;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				ModificarAutomovil inst = new ModificarAutomovil();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public BajaAutomovil() {
		super(titulo);
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1);
				jLabel1.setText("Ingrese Patente");
				jLabel1.setBounds(22, 39, 130, 16);
			}
			{
				campopatente = new JTextField();
				getContentPane().add(campopatente);
				campopatente.setBounds(126, 36, 89, 23);
			}
			{
				buscarboton = new JButton();
				getContentPane().add(buscarboton);
				buscarboton.setText("Buscar");
				buscarboton.setBounds(252, 36, 76, 23);
				buscarboton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						//auto2=AdministradorPersistenciaAutomovil.getInstancia().getAuto(campopatente.getText());
						auto2=Sistema.getSistema().buscarAutomovil(campopatente.getText());
						if (auto2!=null){
							campoestado.setText(auto2.getEstado());
							combcampo.setText(auto2.getCombustible());
							kmcampo.setText(String.valueOf(auto2.getKilometraje()));
							jPanel1.setVisible(true);
						}
						else {
							JOptionPane.showMessageDialog(null, "El Automovil no existe");
					       
						}
					}
				});
			}
			{
				jPanel1 = new JPanel();
				getContentPane().add(jPanel1);
				jPanel1.setBounds(19, 71, 353, 180);
				jPanel1.setLayout(null);
				jPanel1.setVisible(false);
				{
					jLabel2 = new JLabel();
					jPanel1.add(jLabel2);
					jLabel2.setText("Kilometraje");
					jLabel2.setBounds(22, 29, 79, 16);
				}
				{
					kmcampo = new JTextField();
					jPanel1.add(kmcampo);
					kmcampo.setBounds(139, 26, 86, 23);
				}
				{
					jLabel3 = new JLabel();
					jPanel1.add(jLabel3);
					jLabel3.setText("Estado");
					jLabel3.setBounds(22, 75, 51, 16);
				}
				{
					campoestado = new JTextField();
					jPanel1.add(campoestado);
					campoestado.setBounds(139, 72, 86, 23);
				}
				{
					jLabel4 = new JLabel();
					jPanel1.add(jLabel4);
					jLabel4.setText("Combustible");
					jLabel4.setBounds(12, 128, 101, 16);
				}
				{
					combcampo = new JTextField();
					jPanel1.add(combcampo);
					combcampo.setBounds(139, 125, 86, 23);
				}
			}
			{
				jButton1 = new JButton();
				getContentPane().add(jButton1);
				jButton1.setText("Borrar");
				jButton1.setBounds(264, 286, 108, 23);
				jButton1.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
				
						//AdministradorPersistenciaAutomovil.getInstancia().BajaAutomovil(campopatente.getText());
						Sistema.getSistema().eliminarAutomovil(campopatente.getText());
						JOptionPane.showMessageDialog(null, "Se borro el Automovil con Patente " + (campopatente.getText()));
						dispose();
						
						dispose();
					}
				});
			}
			pack();
			this.setSize(400, 358);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
